cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
cmake_policy(SET CMP0054 NEW)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

set(PROJECT_VERSION 0.2.0)
project(SV2SaverDemo VERSION ${PROJECT_VERSION} LANGUAGES CXX C)

add_definitions(-DAPI_EXPORTS)
set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -march=native")
message(STATUS "System:${CMAKE_HOST_SYSTEM_PROCESSOR}")

add_definitions(-DWITH_GSTREAMER)
find_package(SpireMS REQUIRED)
find_package(OpenCV 4 REQUIRED)
#find_package(FFMPEG REQUIRED COMPONENTS avformat avcodec avutil swscale)

message(STATUS "OpenCV library status:")
message(STATUS "    version: ${OpenCV_VERSION}")
message(STATUS "    libraries: ${OpenCV_LIBS}")
message(STATUS "    include path: ${OpenCV_INCLUDE_DIRS}")

message(STATUS "    spirems:${SpireMS_INCLUDE_DIRS}")
message(STATUS "    include path: ${SpireMS_LIBS}")
include_directories(${SpireMS_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/gstreamer)

include_directories(
   "/usr/include/gstreamer-1.0"
   "/usr/local/include/gstreamer-1.0"
   "/usr/include/glib-2.0"
   "/usr/lib/aarch64-linux-gnu/glib-2.0/include"
)

file(GLOB_RECURSE getCode_cpp "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
file(GLOB_RECURSE getCode_c "${CMAKE_CURRENT_SOURCE_DIR}/src/*.c")
file(GLOB_RECURSE getlibgst "${CMAKE_CURRENT_SOURCE_DIR}/src/gstreamer/*.cpp") 
message(STATUS "self code: ${getCode_cpp} -- ${getCode_c}")

#target_link_libraries(sv2_world gstrtspserver-1.0)
#target_link_libraries(sv2_world pthread)
# Demo
add_executable(SV2SaverDemo SV2SaverDemo.cpp ${getCode_c} ${getCode_cpp} ${getlibgst})
target_link_libraries(SV2SaverDemo ${OpenCV_LIBS} ${SpireMS_LIBS} rockit gstbase-1.0 gstreamer-1.0 gstvideo-1.0 gstaudio-1.0 gobject-2.0 glib-2.0 pthread)


install(TARGETS SV2SaverDemo
  RUNTIME DESTINATION bin
)
